#!/bin/bash

PIDFILE=/var/vcap/sys/run/foobar.pid

case $1 in

  start)
    echo $$ > $PIDFILE

    echo "job_name=<%= spec.job.name %>"
    echo "templates=<%= spec.job.templates.map(&:name).sort.join(',') %>"

    exec /bin/sh 'while true; do echo "ZzZzZz..."; sleep 2; done'
    ;;

  stop)
    tail -1 $PIDFILE | xargs kill

    rm -rf $PIDFILE
    ;;

  *)
  echo "Usage: foobar_ctl {start|stop}" ;;
esac

exit 0
